// import Vue from 'vue'
// import Router from 'vue-router'
import Vue from 'vue';
import Pay from '@/router/security/pay';
import Recharge from '@/router/security/recharge';
import Register from '@/router/common/reg';
import Login from '@/router/common/login';
import Myindex from '@/router/my/index';
import Shopindex from '@/router/shopstore/index';
import Exchange from '@/router/shopstore/exchange';
import ExchangeRecords from '@/router/shopstore/records';
import Godinfo from '@/router/god/godinfo';
import Godranking from '@/router/god/ranking';
import MatchAnaylyze from '@/router/matchs/analyze';
import Awaitdou from '@/router/my/awaitgetdou';
import MatchLists from '@/router/matchs/matchslists';
import MatchScore from '@/router/matchs/score';
import Home from '@/router/home/index';
import Billist from '@/router/my/billlist';
import MyRecommend from '@/router/my/recommend';
import CommonRouter from '@/components/CommonRouter';
import RecommendConfig from '@/router/buy/recommendconfig';
import Attentiongod from '@/router/my/attentiongod';
import CollectRecommend from '@/router/my/collectrecommend';
import Details from '@/router/my/details';
import Football from '@/router/buy/football';
import RecommendMatchDetails from '@/router/matchs/recommendinfo';
import PayResult from '@/router/security/payresult';
import store from '@/store/index'
import Applygod from '@/router/god/applygod';
import Index from '@/router/home/home';
import Mycenter from '@/router/my/mycenter'
import Newsinfo from '@/router/news/newsinfo'
import Attestaionphone from '@/router/my/myinfo/attestationphone';
import Realname from '@/router/my/myinfo/realname';
import Blankcards from '@/router/my/myinfo/bankcard';
import Addblankcard from '@/router/my/myinfo/addblankcard';
import NotFound from '@/router/common/404';
import VueRouter from 'vue-router';
if(process.env.NODE_ENV === 'development') {
    Vue.use(VueRouter);
}

import {setDocumentTitle} from '@/uitls/common'
const router = new VueRouter({
    routes: [
        {
            path: '*',
            name: '404',
            component: NotFound,
            meta: {
                title: '懂彩帝'
            },
        },
        {
            path: '/home',
            name: 'hindex',
            component: Index,
            meta: {
                title: '懂彩帝'
            },
        },
        {
            path: '/security',
            name: 'security',
            component: CommonRouter,
            children: [
                {
                    path: 'pay/:planId',
                    name: 'pay',
                    component: Pay,
                    meta: {
                        title: '支付'
                    },
                },
                {
                    path: 'recharge',
                    name: 'recharge',
                    component: Recharge,
                    meta: {
                        title: '充值'
                    },
                },
                {
                    path: 'payresult',
                    name: 'payresult',
                    component: PayResult,
                    meta: {
                        title: '支付结果页'
                    },
                },
            ]
        },
        {
            path: '/buy',
            name: 'buy',
            component: CommonRouter,
            children: [
                {
                    path: 'recommendconfig',
                    name: 'recommendconfig',
                    component: RecommendConfig,
                    meta: {
                        title: '推荐设置'
                    },
                },
                {
                    path: 'football',
                    name: 'football',
                    component: Football,
                    meta: {
                        title: '竞彩足球'
                    },
                },
            ]
        },
        {
            path: '/common',
            name: 'common',
            component: CommonRouter,
            children: [
                {
                    path: 'reg',
                    name: 'reg',
                    component: Register,
                    meta: {
                        title: '注册'
                    },
                },
                {
                    path: 'login',
                    name: 'login',
                    component: Login,
                    meta: {
                        title: '登录'
                    },
                },
            ]
        },
        {
            path: '/my',
            name: 'my',
            redirect: '/my/home',
            component: CommonRouter,
            children: [
                {
                    path: 'home',
                    name: 'home',
                    component: Myindex,
                    meta: {
                        title: '我的'
                    },
                },
                {
                    path: 'center',
                    name: 'center',
                    component: Mycenter,
                    meta: {
                        title: '资料详情'
                    },
                },
                {
                    path: 'center/phone',
                    name: 'centerphone',
                    component: Attestaionphone,
                    meta: {
                        title: '绑定手机号'
                    },
                },
                {
                    path: 'center/realname',
                    name: 'centerrealname',
                    component: Realname,
                    meta: {
                        title: '实名认证'
                    },
                },
                {
                    path: 'center/blankcards',
                    name: 'centerblankcards',
                    component: Blankcards,
                    meta: {
                        title: '我的银行卡'
                    },
                },
                {
                    path: 'center/addblankcard',
                    name: 'centerblankcard',
                    component: Addblankcard,
                    meta: {
                        title: '绑定银行卡'
                    },
                },
                {
                    path: 'awaitgetdou',
                    name: 'awaitgetdou',
                    component: Awaitdou,
                    meta: {
                        title: '待结算的彩豆'
                    },
                },
                {
                    path: 'billists',
                    name: 'billists',
                    component: Billist,
                    meta: {
                        title: '付费阅读'
                    },
                },
                {
                    path: 'myrecommend',
                    name: 'myrecommend',
                    component: MyRecommend,
                    meta: {
                        title: '我的推荐'
                    },
                },
                {
                    path: 'collectrecommend',
                    name: 'collectrecommend',
                    component: CollectRecommend,
                    meta: {
                        title: '收藏推荐'
                    },
                },
                {
                    path: 'attentiongod',
                    name: 'attentiongod',
                    component: Attentiongod,
                    meta: {
                        title: '关注彩帝'
                    },
                },
                {
                    path: 'details',
                    name: 'details',
                    component: Details,
                    meta: {
                        title: '交易详情'
                    },
                },
            ]
        },
        {
            path: '/shop',
            name: 'shop',
            component: CommonRouter,
            children: [
                {
                    path: 'index',
                    name: 'index',
                    component: Shopindex,
                    meta: {
                        title: '彩豆商城'
                    },
                },
                {
                    path: 'exchange/:id',
                    name: 'exchange',
                    component: Exchange,
                    meta: {
                        title: '立即兑换'
                    },
                },
                {
                    path: 'exchangerecords',
                    name: 'exchangerecords',
                    component: ExchangeRecords,
                    meta: {
                        title: '兑换记录'
                    },
                }
            ]
        },
        {
            path: '/god',
            name: 'god',
            component: CommonRouter,
            children: [
                {
                    path: 'godinfo/:godid',
                    name: 'godinfo',
                    component: Godinfo,
                    meta: {
                        title: '彩帝详情'
                    },
                },
                {
                    path: 'godranking',
                    name: 'godranking',
                    component: Godranking,
                    meta: {
                        title: '彩帝排行'
                    },
                }, {
                    path: 'applygod',
                    name: 'applygod',
                    component: Applygod,
                    meta: {
                        title: '申请彩帝'
                    },
                }
            ]
        },
        {
            path: '/matchs',
            name: 'matchs',
            component: CommonRouter,
            children: [
                {
                    path: 'analyze/:id',
                    name: 'analyze',
                    component: MatchAnaylyze,
                    meta: {
                        title: '赛事分析'
                    },
                },
                {
                    path: 'matchlists/:issueNo',
                    name: 'matchlists',
                    component: MatchLists,
                    meta: {
                        title: '赛事列表'
                    },
                },
                {
                    path: 'matchscore',
                    name: 'matchscore',
                    component: MatchScore,
                    meta: {
                        title: '比分列表'
                    },
                },
                {
                    path: 'recommendmatchdetails/:id',
                    name: 'recommendmatchdetails',
                    component: RecommendMatchDetails,
                    meta: {
                        title: '推荐详情'
                    },
                }
            ]
        },
        {
            path: '/news',
            name: 'news',
            component: CommonRouter,
            children: [
                {
                    path: 'info/:id',
                    name: 'info',
                    component: Newsinfo,
                    meta: {
                        title: '帮助中心'
                    },
                },
            ]
        }
    ]
});

router.afterEach(routes => {
    typeof routes.meta.title !== undefined && setDocumentTitle(routes.meta.title);
    setTimeout(function () {
        store.commit('common/updateLoadingStatus', {isLoading: false})
    }, 300)
});

router.beforeEach(function (to, from, next) {
    store.commit('common/updateLoadingStatus', {isLoading: true});
    next()
});

export default router;